<%--
  Created by IntelliJ IDEA.
  User: Dhy
  Date: 2023/9/5
  Time: 20:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>教师编辑</title>
    <link href="../layui/css/layui.css" rel="stylesheet">
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item" style="display: none" >
        <label class="layui-form-label">id</label>
        <div class="layui-input-block">
            <input type="text" name="teacher_id" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="teacher_name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="teacher_password" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="display: none" >
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="text" name="teacher_sex" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-block">
            <input type="text" name="teacher_age" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="editTeacher">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../layui/layui.js"></script>
<script>

    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;
        $ = layui.$;    //全局变量
        console.log(parent.dept);
        console.log(parent.dept.id);
        console.log(parent.dept.phone)

        //通过属性选择器接收
        $('[name="teacher_id"]').attr('value',parent.dept.teacherId);
        $('[name="teacher_name"]').attr('value',parent.dept.teacherName);
        $('[name="teacher_password"]').attr('value',parent.dept.studentPassword);
        $('[name="phone"]').attr('value',parent.dept.phone);
        $('[name="teacher_sex"]').attr('value',parent.dept.teacherSex);
        $('[name="teacher_age"]').attr('value',parent.dept.teacherAge);
        $('[name="title"]').attr('value',parent.dept.title);

        // 提交事件
        form.on('submit(editTeacher)', function(data){
            //防止重复点击
            $(".layui-btn").addClass('layui-btn-disabled');
            $(".layui-btn").attr('disabled','disabled');

            var field = data.field; // 获取表单字段值

            $.ajax({
                url: '${pageContext.request.contextPath}/teacher?method=edit',   // ajax请求地址 地址/开头是接口，直接写是页面
                data: field,  // 请求时传递的参数
                type: 'post',  // 请求的方式，get\post
                dataType: 'json', // 、json
                success: function(result){  // 请求成功时的回调， result请求返回的数据。
                    // debugger
                    // console.log(result);
                    if (result.code === 200){
                        layer.msg("编辑成功");
                        //关闭
                        parent.layer.closeAll('iframe');
                    }else {
                        layer.msg(result.msg);
                    }
                    //解放提交按钮
                    $(".layui-btn").removeClass('layui-btn-disabled');
                    $(".layui-btn").removeAttr('disabled');

                },
                error: function(result){   // 请求失败时的回调
                    console.log(result);
                    layer.msg(result.msg);
                }
            });

            return false; // 阻止默认 form 跳转
        });
    });
</script>
</body>
</html>


